﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Text;
using System.Threading.Tasks;

namespace SubVersionOne
{
    [RunInstaller(true)]
    public class PluginInstaller : Installer
    {
        // Fields
        private IContainer components;

        // Methods
        public PluginInstaller()
        {
            this.InitializeComponent();
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.components = new Container();
        }

        [SecurityPermission(SecurityAction.Demand)]
        public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);
            RegistrationServices services = new RegistrationServices();
            if (!services.RegisterAssembly(base.GetType().Assembly, AssemblyRegistrationFlags.SetCodeBase))
            {
                throw new InstallException("Failed to register for COM Interop.");
            }
        }

        [SecurityPermission(SecurityAction.Demand)]
        public override void Uninstall(IDictionary savedState)
        {
            base.Uninstall(savedState);
            RegistrationServices services = new RegistrationServices();
            if (!services.UnregisterAssembly(base.GetType().Assembly))
            {
                throw new InstallException("Failed to unregister for COM Interop.");
            }
        }

    }
}
